When using the Think C Debugger to develop an application it is possible to use the Monitor command from the Debug menu to drop into a resident debug monitor. The debug monitor allows one to look at register contents, memory contents, and code at the instruction level. While the Think C documentation discusses how the Think C Debugger interfaces with both TMON and Macsbug, the following discussion will be tailored to Macsbug.
If the purpose of entering Macsbug is to look at registers or memory contents, then you need read no further. The facilities of Macsbug as described in its documentation are all that you need. As long as the program counter (PC) register and the stack pointer register (A7) are not disturbed, the "g" command which tells Macsbug to start continuous execution will cause the Think C Debugger to be reentered at the place where the Monitor command was issued, and the source-level debugging operation can continue.
If the purpose of entering Macsbug is to observe behavior of the code by stepping through it instruction by instruction, some preparation is necessary before Macsbug's stepping commands can be used. When Macsbug is entered, the Macintosh has been executing the Think C Debugger. Therefore, the program counter (PC) will contain the address of an instruction in the Debugger, not in the program being debugged (the target program). (The Think C documentation asserts that all other registers will contain values relevant to the target program.) To execute instructions in the target program it is necessary to make the PC point to the proper location in the target program. It is also necessary to remember how to restore the PC so that the Think C Debugger can be reentered. Two Macsbug macros have been defined which simplify this process.
The macros are provided in a Resedit document named "MacsBug/ThinkC Macros". Use Resedit to copy the 'mxbm' resource from "MacsBug/ThinkC Macros" into the "Debugger Prefs" file which is supplied with Macsbug. The "Debugger Prefs" file should be placed in the System folder along with Macsbug.
[It is a good idea that the target program has been compiled with the Think C preferences set to generate Macsbug symbols in the object code.]
After issuing the Monitor command from the Debug menu, the Macsbug screen will appear. The very first thing you should type is "fmtc" (from think c). This the name of the macro which remembers the current PC and sets the PC to point to the target program. Then proceed with whatever Macsbug commands are needed.
When you are ready to return to the Think C Debugger, type "totc" (to think c). This macro will return execution to the Think C Debugger. The arrow indicating the line of C that is next to be executed will not have changed in the source window, although the action in Macsbug may have moved the execution location away from that point. Pressing the Enter key or clicking on the box at the lower left of the source window will cause the debugger to reinterpret where it is, and the source display will update itself to the proper location.
That is all there is to it!
Try to be sure that the PC is pointing inside a routine in the target program for which there is source code to be displayed in the source window of the debugger. When returning to the debugger while the PC is pointing into a library, for instance, the debugger does not always successfully continue working with the target program.
These macros only work when Macsbug has been entered via the Monitor command of the Think C Debugger. If Macsbug is entered in any other way the conditions which the macros assume will not be true, and the result of using them is unpredictable and probably not useful.
These macros have been tested with Macsbug version 6.1 on a Mac Plus running System 6.0.4. It is expected that the macros will work in any environment in which Macsbug 6.1 works.
The author places this information in the public domain. It may be freely used, copied, modified, or distributed. The author takes no responsibility for any consequences of using this material.